subroutine adjust 
use rbf_type
use variable
implicit none
integer  (i4b),dimension(nm)   ::  n_mov_accept_dummy,mov_attempt_dummy
integer (i4b) ::i,tot_spins
real  (dp)   ::  frac,dro
integer :: total_moves=0
save n_mov_accept_dummy,mov_attempt_dummy, total_moves


! ----------- PARA DESPLAZAMIENTO  ------------  !!
tot_spins = 0
succm = 30.d0

do i=1,nm
if(mov_attempt(i)==0.or.mov_attempt_dummy(i)>=mov_attempt(i))then
   
   n_mov_accept_dummy (i)= n_mov_accept(i)
   mov_attempt_dummy  (i)= mov_attempt (i)
   
else
   
   frac = dble(n_mov_accept(i) - n_mov_accept_dummy(i))/ dble(mov_attempt(i)-mov_attempt_dummy(i))
   dro  = dmc(i)
   dmc(i)  = dmc(i)*abs(frac/(succm/100.d0))

   
   if (dmc(i)/dro.gt.1.5d0)            dmc(i) = dro*1.5d0
   if (dmc(i)/dro.lt.0.5d0)            dmc(i) = dro*0.5d0
   if (dmc(i).gt.1.d0)                 dmc(i) = 1.d0
   
  
   tot_spins = tot_spins + (n_mov_accept(i)-n_mov_accept_dummy(i))


   WRITE (6, 998) dmc(i), dro, frac,(mov_attempt(i)-mov_attempt_dummy(i))/1000 , (n_mov_accept(i) - n_mov_accept_dummy(i))/1000 &
                  ,(n_mov_accept(i)-n_mov_accept_dummy(i))
   
   n_mov_accept_dummy(i) = n_mov_accept(i)
   mov_attempt_dummy (i) = mov_attempt (i)
  
endif
enddo

total_moves = total_moves + tot_spins
write(6,992)dble(tot_spins)/1.d6, dble(total_moves)/1.d6,total_moves/nodes

991 format (' Max. displ: ', f10.5, ' (old: ', f10.5, ')', ' frac. acc.: ', f6.2, ' attempts :',i8,'K  succes :',i8,'K  Tot. spins :',I8)
998 format (' Max. displ: ', e12.5, ' (old: ', e12.5, ')', ' frac. acc.: ', f6.2, ' attempts :',i8,'K  succes :',i8,'K  Tot. spins :',I8)
992 format ("total spins moved :",f18.4," M ","  global total moves : ",f18.4," M ","  Moves average per spin  :",I10)


return         
end subroutine adjust
